﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using BLL;
using BLL.Entities;

namespace CorporateGymManagementSystem
{
    /// <summary>
    /// Interaction logic for UpdatePaymentWindow.xaml
    /// </summary>
    public partial class PaymentsWindow : Window
    {
        private Trainee m_Trainee;
        public PaymentsWindow(Trainee i_Trainee)
        {
            m_Trainee = i_Trainee;
            InitializeComponent();
            populateList();
        }

        private void monthSelector_DisplayModeChanged(object sender, CalendarModeChangedEventArgs e)
        {
            if (monthSelector.DisplayMode != CalendarMode.Year)
            {
                monthSelector.DisplayMode = CalendarMode.Year;
                
            }
        }

        private void populateList()
        {
            List<Payment> paymentsList = TraineeManager.GetTraineePaymentHistory(m_Trainee.TraineeId);
            paymentsListBox.ItemsSource = paymentsList;
        }

        private void monthSelector_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            try
            {
                int traineeId = m_Trainee.TraineeId;
                bool addSucceeded = TraineeManager.Instance.AddPayment(m_Trainee, monthSelector.DisplayDate.Month, monthSelector.DisplayDate.Year);
                if (addSucceeded)
                {
                    updateStatusLabel.Content = "Payment Updated";
                    populateList();
                }
                else
                {
                    updateStatusLabel.Content = "Already has payment for this date";
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.StackTrace.ToString());
            }
        }

        private void removePaymentButton_Click(object sender, RoutedEventArgs e)
        {
            if (paymentsListBox.SelectedIndex != -1)
            {
                Payment selectedPayment = paymentsListBox.SelectedItem as Payment;
                TraineeManager.Instance.RemovePayment(selectedPayment);
                populateList();
            }

        }
    }
}
